/**
 * Project: push-center-biz-dal
 * 
 * File Created at 2014年10月9日
 * 
 * Copyright 2012 Greenline.com Corporation Limited.
 * All rights reserved.
 *
 * This software is the confidential and proprietary information of
 * Greenline Company. ("Confidential Information").  You shall not
 * disclose such Confidential Information and shall use it only in
 * accordance with the terms of the license agreement you entered into
 * with Greenline.com.
 */
package com.greenline.push.dal.pushcenter.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.greenline.push.dal.base.BaseDAO;
import com.greenline.push.dal.pushcenter.MsgForSendDao;
import com.greenline.push.dal.pushcenter.dataobject.MsgForSendDO;
import com.greenline.push.dal.query.MsgForSendQuery;

/**
 * @Type GroupUserDAOImpl
 * @Desc
 * @author shuai.zuo
 * @date 2014年10月9日
 * @Version V1.0
 */
public class MsgForSendDAOImpl extends BaseDAO implements MsgForSendDao {

    /*
     * (non-Javadoc)
     * 
     * @see com.greenline.push.dal.pushcenter.GroupUserDao#insert(com.greenline.
     * push.dal.pushcenter.dataobject.groupUserDO)
     */
    @Override
    public Long insert(MsgForSendDO msgForSendDO) {
        return (Long) super.getSqlMapClientTemplate().insert("msgForSend.insert", msgForSendDO);
    }

    /*
     * (non-Javadoc)
     * 
     * @see com.greenline.push.dal.pushcenter.groupUserDAO#getgroupUserById(java
     * .lang.Long)
     */
    @Override
    public MsgForSendDO getById(Long id) {
        return (MsgForSendDO) super.getSqlMapClientTemplate().queryForObject("msgForSend.find_by_id", id);
    }

    /*
     * (non-Javadoc)
     * 
     * @see com.greenline.push.dal.pushcenter.groupUserDAO#update(com.greenline.
     * push.dal.pushcenter.dataobject.groupUserDO)
     */
    @Override
    public int update(MsgForSendDO msgForSendDO) {
        return super.getSqlMapClientTemplate().update("msgForSend.update", msgForSendDO);
    }

    /*
     * (non-Javadoc)
     * 
     * @see
     * com.greenline.push.dal.pushcenter.groupUserDAO#listByQuery(com.greenline
     * .push.dal.query.groupUserQuery)
     */
    @Override
    public MsgForSendQuery listByQuery(MsgForSendQuery query) {
        return (MsgForSendQuery) super.listByQuery("msgForSend.list_by_query", query);
    }

    @Override
    public int deleteById(Long id) {
        return super.getSqlMapClientTemplate().update("msgForSend.delete", id);
    }

    @Override
    public MsgForSendDO getLastedRecord() {
        return (MsgForSendDO) super.getSqlMapClientTemplate().queryForObject("msgForSend.get_last_record");
    }

    @SuppressWarnings("unchecked")
    @Override
    public List<MsgForSendDO> getRealTimeMsgForSendList(Long maxMsgId, Integer count) {
        Map<String, Object> param = new HashMap<String, Object>();
        param.put("maxMsgId", maxMsgId);
        param.put("count", count);
        return (List<MsgForSendDO>) super.getSqlMapClientTemplate().queryForList("msgForSend.get_realtime_by_maxid", param);
    }

    @SuppressWarnings("unchecked")
    @Override
    public List<MsgForSendDO> getPeriodicMsgForSendList(Long maxMsgId, Integer count) {
        Map<String, Object> param = new HashMap<String, Object>();
        param.put("maxMsgId", maxMsgId);
        param.put("count", count);
        return (List<MsgForSendDO>) super.getSqlMapClientTemplate().queryForList("msgForSend.get_periodic_by_maxid", param);
    }

    @Override
    public boolean resetStatus(Long lastId) {
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("id", lastId);
        super.getSqlMapClientTemplate().update("msgForSend.reset_status", map);
        return true;
    }

    @SuppressWarnings("unchecked")
    @Override
    public List<MsgForSendDO> fetchByTypeAndRecord(Integer type, Long record, Integer total) {
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("type", type);
        map.put("record", record);
        map.put("total", total);

        return super.getSqlMapClientTemplate().queryForList("msgForSend.fetch_by_type_record", map);
    }

}
